package masterjava.common.client.gxt.base.util;

import com.extjs.gxt.ui.client.data.ModelData;
import masterjava.common.shared.util.SharedUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * User: gkislin
 * Date: 7/19/11
 */
public class GxtUtil {
    public interface ToModel<T, M extends ModelData> {
        M toModel(T entity);
    }

    public static <T, M extends ModelData> List<M> convertToModelList(List<T> list, ToModel<T, M> converter) {
        if (SharedUtil.isEmpty(list)) {
            return Collections.EMPTY_LIST;
        }
        ArrayList<M> modelList = new ArrayList<M>(list.size());
        for (T item : list) {
            modelList.add(converter.toModel(item));
        }
        return modelList;
    }
}
